import React, { Component } from "react";

export default class Obj extends Component {
    constructor () {
        super();
        this.state = {
            info: {
                username: "leson",
                userage: 18,
            },
        };
    }

    add() {//新增的方法
        this.setState({
            info: { ...this.state.info, userage: this.state.info.userage + 1 }
        })

    };
    render() {
        return (
            <div>
                Child4
                <div>
                    <button
                        onClick={() => {
                            this.add();
                        }}
                    >
                        点击新增年龄
                    </button>
                    {this.state.info.username}
                    今年{this.state.info.userage}
                </div>
            </div>
        );
    }
}